﻿<?php
	error_reporting(E_ALL^E_NOTICE);
	require_once ('../config/config.php'); 
	require_once ('../config/email.class.php'); 
	session_start();
	if(!empty($_SESSION['member'])){
		echo "<script>location='./index.php';</script>";
	}
	if($_POST['submit']){
	    $user=$_POST['user'];
	    $userRs=mysqli_fetch_array(mysqli_query($con,"select * from member where user='".$user."'"));
	    if($userRs['user']==""){
			echo "<script>alert('此账号不存在！');history.back();</script>";
	    }else{
	        $_SESSION['forgotUser']=$userRs['user'];
	    }
	    
	}
	if($_POST['submit2']){
	    $email=$_POST['email'];
	    $rs=mysqli_fetch_array(mysqli_query($con,"select * from member where user='".$_SESSION['forgotUser']."'"));
	    if($rs['email']==$email){
			$newPwd=getkey(8);
			mysqli_query($con,"update member set password='".md5($newPwd)."' where user='".$_SESSION['forgotUser']."'");
			$smtpserver = "smtp.mxhichina.com";//SMTP服务器
			$smtpserverport ="25";//SMTP服务器端口
			$smtpusermail = "";//SMTP服务器的用户邮箱
			$smtpemailto = $email;//发送给谁
			$smtpuser = "";//SMTP服务器的用户帐号
			$smtppass = "";//SMTP服务器的用户密码
			$mailsubject = "【校园兼职网站】-密码找回";//邮件主题
			$mail = new StdClass;
			$mail->FromName = "【校园兼职网站】";
			$mailbody = "<div backgroud='seashell' id='contentDiv' onmouseover='getTop().stopPropagation(event);' onclick='getTop().preSwapLink(event, 'html', 'ZC2306-nkpgO9wi6NnbD1EOMO2hGa7');' style='position:relative;font-size:14px;height:auto;padding:15px 15px 10px 15px;z-index:1;zoom:1;line-height:1.7;' class='body'><div id='qm_con_body'><div id='mailContentContainer' class='qmbox qm_con_body_content qqmail_webmail_only'><div style='width:700px;background-color:#fff;margin:0 auto;border: 1px solid #ccc;'><div style='height:64px;margin:0;padding:0;width:100%;'><a href='".$_SERVER['SERVER_NAME']."' style='display:block;padding: 12px 30px;text-decoration: none;font-size: 24px;letter-spacing: 3px;border-bottom: 1px solid #ccc;' rel='noopener' target='_blank'> 校园兼职网站 </a></div><div style='padding: 30px;margin:0;'><p style='font-size:14px;color:#333;'> 您的帐号为：<span style='font-size:14px;color:#333;'><a rel='noopener' target='_blank'>".$_SESSION['forgotUser']."</a></span>，正在进行密码重置！ </p><p style='font-size:14px;color:#333;'>新密码为：".$newPwd."</p><p style='font-size:14px;color: #999;'>— 校园兼职网站</p><p style='font-size:12px;color:#999;border-top:1px dotted #E3E3E3;margin-top:30px;padding-top:30px;'> 本邮件为系统邮件，请勿回复。 </p></div></div><style type='text/css'>.qmbox style, .qmbox script, .qmbox head, .qmbox link, .qmbox meta {display: none !important;}</style></div></div><style>#mailContentContainer .txt {height:auto;}</style></div>";//邮件内容
			$mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
			$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
			$smtp->debug = false;//是否显示发送的调试信息
			$av=$smtp->sendmail($smtpemailto,$smtpusermail, $mailsubject,$mailbody,$mailtype);
			if($av!="1"){
				unset($_SESSION['forgotUser']);
				echo "<script>alert('系统发生异常，邮件未送达！');location='./forgot.php';</script>";
			}else{
				unset($_SESSION['forgotUser']);
				echo "<script>alert('新密码已妥投到 ：".$email." ,如果存在问题，请联系客服或工程师进行处理！');location='./signin.php';</script>";
			}
	    }else{
			unset($_SESSION['forgotUser']);
	        echo "<script>alert('此邮箱未绑定此账号，请检查后重试！');history.back();</script>";
	    }
	    
	}
?>
<html lang="zh-CN" class="translated-ltr"><head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

	<!-- CSS -->
	<link rel="stylesheet" href="css/bootstrap-reboot.min.css">
	<link rel="stylesheet" href="css/bootstrap-grid.min.css">
	<link rel="stylesheet" href="css/owl.carousel.min.css">
	<link rel="stylesheet" href="css/nouislider.min.css">
	<link rel="stylesheet" href="css/select2.min.css">
	<link rel="stylesheet" href="css/jquery.mCustomScrollbar.min.css">
	<link rel="stylesheet" href="css/ionicons.min.css">
	<link rel="stylesheet" href="css/main.css">

	<!-- Favicons -->
	<link rel="icon" type="image/png" href="icon/favicon-32x32.png" sizes="32x32">
	<link rel="apple-touch-icon" href="icon/favicon-32x32.png">
	<link rel="apple-touch-icon" sizes="72x72" href="icon/apple-touch-icon-72x72.png">
	<link rel="apple-touch-icon" sizes="114x114" href="icon/apple-touch-icon-114x114.png">
	<link rel="apple-touch-icon" sizes="144x144" href="icon/apple-touch-icon-144x144.png">

	<meta name="description" content="">
	<meta name="keywords" content="">
	<meta name="author" content="Dmitry Volkov">
	<title>学校兼职网站 - 忘记密码</title>
<link type="text/css" rel="stylesheet" charset="UTF-8" href="https://translate.googleapis.com/translate_static/css/translateelement.css"></head>

<body>
	<div class="sign">
		<div class="container">
			<div class="row">
				<div class="col-12">
					<div class="sign__content">
						<!-- authorization form -->
						<form action="./forgot.php" method="post" class="sign__form">
							<?php
								if($_SESSION['forgotUser']){?>
									<div class="sign__group">
										<input name="email" type="email" class="sign__input" placeholder="请输入电子邮件">
									</div>
							<?php
								}else{?>
									<div class="sign__group">
										<input name="user" type="text" class="sign__input" placeholder="请输入账号">
									</div>
							<?php
								}
							?>
							<?php
								if($_SESSION['forgotUser']){?>
									<input class="sign__btn" type="submit" name="submit2" value="下一步">
							<?php
								}else{?>
									<input class="sign__btn" type="submit" name="submit" value="下一步">
							<?php
								}
							?>

							<!--<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;由于华为云限制服务器使用25端口发信，我们暂时无法为您提供密码找回服务！如果您忘记密码，请联系管理员！</font></font></h4><br />-->
							<br /><br /><br /><a href="./signin.php"><button class="sign__btn" type="button"><span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></font></span></button></a>
						</form>
						<!-- end authorization form -->
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- JS -->
	<script src="js/jquery-3.4.1.min.js"></script>
	<script src="js/bootstrap.bundle.min.js"></script>
	<script src="js/owl.carousel.min.js"></script>
	<script src="js/wNumb.js"></script>
	<script src="js/nouislider.min.js"></script>
	<script src="js/select2.min.js"></script>
	<script src="js/jquery.mousewheel.min.js"></script>
	<script src="js/jquery.mCustomScrollbar.min.js"></script>
	<script src="js/main.js"></script><div id="goog-gt-tt" class="skiptranslate" dir="ltr"><div style="padding: 8px;"><div><div class="logo"><img src="https://www.gstatic.com/images/branding/product/1x/translate_24dp.png" width="20" height="20" alt="Google 翻译"></div></div></div><div class="top" style="padding: 8px; float: left; width: 100%;"><h1 class="title gray">原文</h1></div><div class="middle" style="padding: 8px;"><div class="original-text"></div></div><div class="bottom" style="padding: 8px;"><div class="activity-links"><span class="activity-link">提供更好的翻译建议</span><span class="activity-link"></span></div><div class="started-activity-container"><hr style="color: #CCC; background-color: #CCC; height: 1px; border: none;"><div class="activity-root"></div></div></div><div class="status-message" style="display: none;"></div></div>

<div class="goog-te-spinner-pos"><div class="goog-te-spinner-animation"><svg xmlns="http://www.w3.org/2000/svg" class="goog-te-spinner" width="96px" height="96px" viewBox="0 0 66 66"><circle class="goog-te-spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div></div></body></html>